<!DOCTYPE html>
<html>
<head>
<title>Molecular Beam Apparatus</title>
<style>
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background-color: #f0f0f0;
  }
  canvas {
    border: 1px solid #ccc;
    background-color: #fff;
  }
</style>
</head>
<body>
<canvas id="myCanvas" width="600" height="450"></canvas>
<script>
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');

// Style settings
ctx.lineWidth = 2;
ctx.strokeStyle = 'black';
ctx.fillStyle = 'black';
ctx.font = "20px sans-serif";

// --- Draw Oven ---
ctx.strokeRect(50, 150, 100, 100);
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText('oven', 100, 200);

// --- Draw Vacuum Chamber ---
ctx.beginPath();
// Top wall
ctx.moveTo(150, 100);
ctx.lineTo(550, 100);
// Right wall
ctx.lineTo(550, 300);
// Bottom wall part 1
ctx.lineTo(500, 300);
// Pump outlet top
ctx.lineTo(500, 340);
ctx.moveTo(450, 340); // Move to the other side of the outlet
ctx.lineTo(450, 300);
// Bottom wall part 2
ctx.lineTo(150, 300);
// Left wall (around oven opening)
ctx.lineTo(150, 250); // Connect to bottom of oven
ctx.moveTo(150, 150); // Move to top of oven
ctx.lineTo(150, 100); // Connect to top wall
ctx.stroke();

// --- Draw Collimating Slits ---
// Slit 1
ctx.beginPath();
ctx.moveTo(280, 160);
ctx.lineTo(280, 195);
ctx.moveTo(280, 205);
ctx.lineTo(280, 240);
ctx.stroke();

// Slit 2
ctx.beginPath();
ctx.moveTo(380, 160);
ctx.lineTo(380, 195);
ctx.moveTo(380, 205);
ctx.lineTo(380, 240);
ctx.stroke();

// --- Draw Molecular Beam (Dashed Lines) ---
ctx.save();
ctx.setLineDash([6, 4]);
ctx.beginPath();
// Top dashed line (calculated to show slight divergence)
ctx.moveTo(150, 196.3);
ctx.lineTo(550, 192.3);
// Bottom dashed line (calculated to show slight divergence)
ctx.moveTo(150, 203.7);
ctx.lineTo(550, 207.7);
ctx.stroke();
ctx.restore(); // Restore to solid lines

// --- Draw Pump Connection ---
// Arrow shaft
ctx.beginPath();
ctx.moveTo(475, 340);
ctx.lineTo(475, 370);
// Arrow head
ctx.moveTo(470, 362);
ctx.lineTo(475, 370);
ctx.lineTo(480, 362);
ctx.stroke();

// --- Add Text Labels ---
// 'collimating slits'
ctx.textAlign = 'center';
ctx.textBaseline = 'bottom';
ctx.fillText('collimating slits', 330, 150);

// 'vacuum'
ctx.textAlign = 'center';
ctx.textBaseline = 'bottom';
ctx.fillText('vacuum', 430, 290);

// 'to pump'
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.fillText('to pump', 475, 375);

// 'Fig. 2.40.'
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.fillText('Fig. 2.40.', 330, 420);

</script>
</body>
</html>